package cn.nubia.admin.api.jinshan.helper;

import org.springframework.core.io.ClassPathResource;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

/**
 * 错误信息处理
 * Created by wangj on 2015/7/24.
 */
public class ErrorMessageHelper {

    private final static Properties ERROR_CODE_INFO;

    public final static String VIRUS_DESC = "virus_desc";

    public final static String AD_ACTION = "ad_action";

    public final static String AD_TYPE = "ad_type";

    public final static String CHECK_RESULT = "check_result";

    public final static String CHECK_REQUEST = "check_req";

    static {
        ERROR_CODE_INFO = new Properties();
        ClassPathResource classPathResource = new ClassPathResource("evil.properties");
        try {
            BufferedReader bf = new BufferedReader(new InputStreamReader(classPathResource.getInputStream()));
            ERROR_CODE_INFO.load(bf);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static List<String> getMessages(String prefix , List<Integer> codes) {
        List<String> messages = new ArrayList<>();
        for (Integer code : codes) {
            messages.add(getMessage(prefix, code));
        }
        return messages;
    }

    public static String getMessage(String prefix, Integer code) {
        StringBuilder sb = new StringBuilder();
        sb.append(prefix).append(".").append(code);
        return ERROR_CODE_INFO.getProperty(sb.toString());
    }
}
